package cn.aaalei.shorturl.controller;

import cn.aaalei.shorturl.service.ResolveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class ResolveController {

    @Autowired
    private ResolveService resolveService;

    @RequestMapping("/{hash}")
    public String forwardUrl(@PathVariable String hash){
        String url = resolveService.getTruthUrl(hash);
        if (url == null){
            return "redirect:http://aaalei.cn/";
        }
        System.out.println(url);
        return "redirect:" + url;
    }
}
